package com.example.work4.http;

import android.content.Context;
import android.graphics.Region;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import com.example.work4.common.FIN;
import com.qiniu.android.common.Zone;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UpProgressHandler;
import com.qiniu.android.storage.UploadManager;
import com.qiniu.android.storage.UploadOptions;

import org.json.JSONObject;



public class QiniuUpload {
    private final UploadManager uploadManager = new UploadManager(new Configuration.Builder().zone(Zone.zone2).build());
    public Handler handler = null;

    public void uploadImg(String filePath,String uploadName,String token){
        uploadManager.put(filePath, uploadName, token, new UpCompletionHandler() {
            @Override
            public void complete(String key, ResponseInfo info, JSONObject response) {
                if(info.statusCode == 200){
                    Message message = new Message();
                    message.what = FIN.INSTANCE.getIMAGEURI();
                    message.obj = key;
                    handler.sendMessage(message);
                }
            }
        },new UploadOptions(null, null, false, new UpProgressHandler() {
            @Override
            public void progress(String key, double percent) {

            }
        },null)
        );
    }

}
